import axios from "axios";
// import { config } from "vue/types/umd";
//创建实例
const instance = axios.create({
    baseURL: "",
});
//拦截器

//设置一个超时时间

instance.defaults.timeout = 30 * 1000;
//请求拦截器
axios.interceptors.request.use(
    (config) => {
        console.log("发请求");
        return config;
    },

    (error) => {
        return Promise.reject(error);
    }
);
//响应拦截器
instance.interceptors.response.use(
    (response) => {
        console.log("回来了");
        const { data } = response;
        if (data.code === 200) {
            return data;
            //相当于rosolve
        } else {
            return Promise.reject(data);
        }
    },
    (error) => {
        return Promise.reject(error);
    }
);

export default instance;